from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-29 14:11:49.238921
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 29, Sep, 2022
Time: 14:11:54
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.5443
Nobs: 794.000 HQIC: -50.8707
Log likelihood: 10226.8 FPE: 6.58660e-23
AIC: -51.0744 Det(Omega_mle): 5.88493e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299370 0.053271 5.620 0.000
L1.Burgenland 0.108861 0.035718 3.048 0.002
L1.Kärnten -0.106484 0.019001 -5.604 0.000
L1.Niederösterreich 0.208308 0.074658 2.790 0.005
L1.Oberösterreich 0.102626 0.071691 1.432 0.152
L1.Salzburg 0.251929 0.038086 6.615 0.000
L1.Steiermark 0.037405 0.049825 0.751 0.453
L1.Tirol 0.106466 0.040376 2.637 0.008
L1.Vorarlberg -0.059095 0.034713 -1.702 0.089
L1.Wien 0.054985 0.064041 0.859 0.391
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.062760 0.110408 0.568 0.570
L1.Burgenland -0.033242 0.074029 -0.449 0.653
L1.Kärnten 0.047728 0.039380 1.212 0.226
L1.Niederösterreich -0.170773 0.154735 -1.104 0.270
L1.Oberösterreich 0.384392 0.148586 2.587 0.010
L1.Salzburg 0.287998 0.078936 3.649 0.000
L1.Steiermark 0.106320 0.103266 1.030 0.303
L1.Tirol 0.313934 0.083682 3.752 0.000
L1.Vorarlberg 0.024987 0.071944 0.347 0.728
L1.Wien -0.017382 0.132729 -0.131 0.896
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190714 0.027382 6.965 0.000
L1.Burgenland 0.089820 0.018360 4.892 0.000
L1.Kärnten -0.008479 0.009767 -0.868 0.385
L1.Niederösterreich 0.263742 0.038376 6.873 0.000
L1.Oberösterreich 0.126742 0.036851 3.439 0.001
L1.Salzburg 0.047720 0.019577 2.438 0.015
L1.Steiermark 0.016968 0.025611 0.663 0.508
L1.Tirol 0.094217 0.020754 4.540 0.000
L1.Vorarlberg 0.059184 0.017843 3.317 0.001
L1.Wien 0.120405 0.032918 3.658 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108482 0.028028 3.871 0.000
L1.Burgenland 0.044652 0.018793 2.376 0.018
L1.Kärnten -0.016117 0.009997 -1.612 0.107
L1.Niederösterreich 0.193686 0.039281 4.931 0.000
L1.Oberösterreich 0.293446 0.037720 7.780 0.000
L1.Salzburg 0.115280 0.020038 5.753 0.000
L1.Steiermark 0.100356 0.026215 3.828 0.000
L1.Tirol 0.116227 0.021243 5.471 0.000
L1.Vorarlberg 0.070801 0.018264 3.877 0.000
L1.Wien -0.027076 0.033694 -0.804 0.422
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129215 0.050823 2.542 0.011
L1.Burgenland -0.051681 0.034077 -1.517 0.129
L1.Kärnten -0.040220 0.018127 -2.219 0.027
L1.Niederösterreich 0.170962 0.071227 2.400 0.016
L1.Oberösterreich 0.138586 0.068397 2.026 0.043
L1.Salzburg 0.286136 0.036335 7.875 0.000
L1.Steiermark 0.034420 0.047535 0.724 0.469
L1.Tirol 0.163885 0.038520 4.255 0.000
L1.Vorarlberg 0.103860 0.033117 3.136 0.002
L1.Wien 0.067151 0.061097 1.099 0.272
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060461 0.040314 1.500 0.134
L1.Burgenland 0.038542 0.027031 1.426 0.154
L1.Kärnten 0.050596 0.014379 3.519 0.000
L1.Niederösterreich 0.224936 0.056499 3.981 0.000
L1.Oberösterreich 0.281665 0.054254 5.192 0.000
L1.Salzburg 0.050807 0.028822 1.763 0.078
L1.Steiermark -0.006402 0.037706 -0.170 0.865
L1.Tirol 0.149901 0.030555 4.906 0.000
L1.Vorarlberg 0.071213 0.026269 2.711 0.007
L1.Wien 0.079213 0.048464 1.634 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178980 0.048198 3.713 0.000
L1.Burgenland -0.006123 0.032317 -0.189 0.850
L1.Kärnten -0.061171 0.017191 -3.558 0.000
L1.Niederösterreich -0.083142 0.067548 -1.231 0.218
L1.Oberösterreich 0.192419 0.064864 2.967 0.003
L1.Salzburg 0.057081 0.034459 1.657 0.098
L1.Steiermark 0.230726 0.045080 5.118 0.000
L1.Tirol 0.493838 0.036531 13.518 0.000
L1.Vorarlberg 0.049457 0.031407 1.575 0.115
L1.Wien -0.049697 0.057942 -0.858 0.391
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160865 0.055342 2.907 0.004
L1.Burgenland -0.011261 0.037107 -0.303 0.762
L1.Kärnten 0.065977 0.019739 3.342 0.001
L1.Niederösterreich 0.201229 0.077561 2.594 0.009
L1.Oberösterreich -0.061391 0.074479 -0.824 0.410
L1.Salzburg 0.215514 0.039566 5.447 0.000
L1.Steiermark 0.114160 0.051762 2.205 0.027
L1.Tirol 0.076721 0.041946 1.829 0.067
L1.Vorarlberg 0.124420 0.036062 3.450 0.001
L1.Wien 0.115975 0.066530 1.743 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356204 0.032157 11.077 0.000
L1.Burgenland 0.006904 0.021561 0.320 0.749
L1.Kärnten -0.023593 0.011470 -2.057 0.040
L1.Niederösterreich 0.222927 0.045067 4.947 0.000
L1.Oberösterreich 0.176117 0.043277 4.070 0.000
L1.Salzburg 0.047018 0.022991 2.045 0.041
L1.Steiermark -0.018731 0.030077 -0.623 0.533
L1.Tirol 0.108760 0.024373 4.462 0.000
L1.Vorarlberg 0.073178 0.020954 3.492 0.000
L1.Wien 0.052420 0.038658 1.356 0.175
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041191 0.152562 0.191606 0.157492 0.125335 0.114052 0.066105 0.224796
Kärnten 0.041191 1.000000 -0.002554 0.129634 0.041387 0.096202 0.429741 -0.053212 0.101831
Niederösterreich 0.152562 -0.002554 1.000000 0.337509 0.154862 0.300762 0.110714 0.183820 0.327010
Oberösterreich 0.191606 0.129634 0.337509 1.000000 0.232301 0.333486 0.172759 0.172245 0.264699
Salzburg 0.157492 0.041387 0.154862 0.232301 1.000000 0.146376 0.126505 0.149159 0.136750
Steiermark 0.125335 0.096202 0.300762 0.333486 0.146376 1.000000 0.153114 0.140701 0.081083
Tirol 0.114052 0.429741 0.110714 0.172759 0.126505 0.153114 1.000000 0.114624 0.155152
Vorarlberg 0.066105 -0.053212 0.183820 0.172245 0.149159 0.140701 0.114624 1.000000 0.007390
Wien 0.224796 0.101831 0.327010 0.264699 0.136750 0.081083 0.155152 0.007390 1.000000